﻿using System.Windows;
using MyFloridaHouse.libSvOpenDistricts.Dialogs;
using System;
using MyFloridaHouse.libSvUtilities.Logging;
using MyFloridaHouse.libSvOpenDistricts.enumerations;
using MyFloridaHouse.libSvDTO;
using MyFloridaHouse.libSvOpenDistricts.PDF;
using System.Windows.Controls;

namespace MyFloridaHouse.libSvOpenDistricts.ViewModel
{
    public partial class ViewModelBase
    {

        public DistrictPlanPrintPdfDlg districtPlanPrintPdfDlg;


        private bool CmdReportsDistrictPlanPDFCanExecute(object parameter)  
        {
            return ((districtPlan.districtCount > 0) & (!isDialogOpen));
        }

        private void CmdReportsDistrictPlanPDFExecute(object parameter)
        {
            try
            {
                ReserveDialog(CmdReportsDistrictPlanPDF);
                districtPlanPrintPdfDlg = new DistrictPlanPrintPdfDlg(OnMemberPropertyChanged, DisplayPanelForDialogs, districtPlan.districtPlanName, districtPlan.districtCount, new BoundingBoxDTO(mapLatLonNW.Latitude, mapLatLonNW.Longitude, mapLatLonSE.Latitude, mapLatLonSE.Longitude));
                districtPlanPrintPdfDlg.Start(CmdReportsDistrictPlanPDFDone);
            }
            catch (Exception ex)
            {
                Log.NotifyUser("Error starting PDF print : " + ex.Message);
            }
        }

        private void CmdReportsDistrictPlanPDFDone(bool result)
        {
            try
            {
                if (result)
                {
                    DistrictPlanPDFPrint(districtPlanPrintPdfDlg.PDFPrintDistricttPlanTitle
                                        , districtPlanPrintPdfDlg.currentViewBoundingBox
                                        , districtPlanPrintPdfDlg.selectedPlanPDFPrintPaperSize
                                        , districtPlanPrintPdfDlg.selectedDistrictPlanPDFPrintMapArea
                                        , districtPlanPrintPdfDlg.selectedDistrict);
                }
            }
            catch (Exception ex)
            {
                Log.NotifyUser("Unable to write district plan to PDF : " + ex.Message);
            }
            finally
            {
                ReleaseDialog(CmdReportsDistrictPlanPDF);
            }
        }

    }
}


